package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.dafuweng.DFWBossData;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.DaFuWengActivity;
import com.yanqu.road.server.manager.cross.battle.DaFuWengMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = Protocol.C_CROSS_DA_FU_WENG_SKIP_BOSS_EVENT, desc = "跨服跳过boss事件")
public class CrossSkipBossEventCmd extends CrossUnionCommand {

    int activityId;
    int bossId;
    long serverId;
    long userId;

    boolean canSkip = false;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.CrossSkipBossEventReqMsg reqMsg = MonopolyProto.CrossSkipBossEventReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        bossId = reqMsg.getBossId();
        serverId = reqMsg.getServerId();
        userId = reqMsg.getUserId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DaFuWengActivity activity = DaFuWengMgr.getDaFuWengActivity(activityId, groupId);
        if (activity != null) {
            DFWBossData bossData = activity.getBossDataById(bossId);
            canSkip = bossData.getKillerUserId() != 0;

            MonopolyProto.CrossSkipBossEventRespMsg.Builder builder = MonopolyProto.CrossSkipBossEventRespMsg.newBuilder();
            builder.setActivityId(activityId);
            builder.setBossId(bossId);
            builder.setCanSkip(canSkip);
            YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(GameProtocol.S_DA_FU_WENG_SKIP_BOSS_EVENT_FROM_CROSS, builder);
            MessageHelper.sendPacket(serverId, userId, yanQuMessage);
        }
    }

    @Override
    public void sendData() {

    }
}
